import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @Author: hs
 * @Description:
 * @Date: Create in 15:29 2019/8/26
 */
public class Mather {
    public static void main(String[] args) {
        Map<String,String> map = new HashMap<>();
        map.put("dd1.df","huangshun");
        map.put("ddd.f","1024");
        String name = "123${dfdf:e1ee}sdfsdf${dd1.df},#{ddd.f}sdfsd";
        Pattern compile = Pattern.compile("([$#]\\{){1,1}[0-9a-zA-Z:\\.]+[}]{1,1}");
        //Pattern compile = Pattern.compile("([$#]\\{){1,1}([^}.]+)+[}]{1,1}");
        Matcher matcher = compile.matcher(name);
        while (matcher.find()) {
            String group = matcher.group();
            String substring = group.substring(2, group.length() - 1);
            System.out.print(matcher.group()+":"+substring+"  ");
            String defaultValue = "";
            if(substring.contains(":")){
                String[] split = substring.split(":");
                substring = split[0];
                defaultValue = split[1];
            }
            String s = map.get(substring);
            if(s!=null){
                name = name.replace(group,map.get(substring));
            }else if(defaultValue !=null && !defaultValue.equals("")){
                name = name.replace(group,defaultValue);
            }

            System.out.print(matcher.start()+"-");
            System.out.println(matcher.end());
            System.out.println(name);
        }
    }
}
